//
// Created by Ukua on 2024/3/25.
//

#ifndef JUSTFW_DM_MOTORS_H
#define JUSTFW_DM_MOTORS_H

#include "interface.h"
#include "tinybus.h"

#define DM_MOTOR_NUM 6

//电机型号
typedef enum DM_Motor{
    DM_J8006,
    DM_H6215,
}DM_MotorTypeDef;

typedef struct DM_Config {
    uint32_t motor_id;
    char *motor_ptr_name;//共享指针名
    DM_MotorTypeDef motor_type;
    float angle_offset;
    float direction;//电机方向（电机角度、输出乘以该系数，设置-1反向）
    INTF_Motor_ModeTypeDef motor_mode; //运行模式
    char *can_rx_topic_name;
    char *can_tx_topic_name;
    float kp;//运控模式kp
    float kd;//运控模式kd
}DM_ConfigTypeDef;

//#define P_MIN (-12.5f)
//#define P_MAX 12.5f
//#define V_MIN (-45.0f)
//#define V_MAX 45.0f
//#define KP_MIN 0.0f
//#define KP_MAX 500.0f
//#define KD_MIN 0.0f
//#define KD_MAX 5.0f
//#define T_MIN (-20.0f)
//#define T_MAX 20.0f
//#define A_MIN (-4*3.1415926535)
//#define A_MAX 4*3.1415926535

//默认电机参数
//const float J8006_ConstRes[10]={P_MIN,P_MAX,V_MIN,V_MAX,KP_MIN,KP_MAX,KD_MIN,KD_MAX,T_MIN,T_MAX,A_MIN,A_MAX};
const static float DM_J8006_ConstRes[12]={-12.5f,12.5f,-45.0f,45.0f,0.0f,500.0f,0.0f,5.0f,-20.0f,20.0f,-4*3.1415926535,4*3.1415926535};
const static float DM_H6215_ConstRes[12]={-12.5f,12.5f,-45.0f,45.0f,0.0f,500.0f,0.0f,5.0f,-10.0f,10.0f,-4*3.1415926535,4*3.1415926535};


union DM_ConstRes{
    float data[12];
    struct {
        float P_MIN;
        float P_MAX;
        float V_MIN;
        float V_MAX;
        float KP_MIN;
        float KP_MAX;
        float KD_MIN;
        float KD_MAX;
        float T_MIN;
        float T_MAX;
        float A_MIN;
        float A_MAX;
    };
};

typedef struct DM_ResData{
    float angle_offset;
    Bus_SubscriberTypeDef *can_rx_topic;
    Bus_TopicHandleTypeDef *can_tx_topic;
    union DM_ConstRes const_res; //电机参数
    DM_MotorTypeDef motor_type;
    float kp;//MIT模式kp
    float kd;//MIT模式kd
}DM_ResDataTypeDef;

void DM_Init();

#endif //JUSTFW_DM_MOTORS_H
